<?php

include_once $_SERVER['DOCUMENT_ROOT'].'HelmesWorkTest/frontend/controller/commands/Command.php';
include_once $_SERVER['DOCUMENT_ROOT'].'HelmesWorkTest/backend/services/implementations/PersonSectorInvolvementServiceImpl.php';
include_once $_SERVER['DOCUMENT_ROOT'].'HelmesWorkTest/frontend/controller/formconverters/PersonSectorInvolvementFormConverter.php';

/**
 * Description of FillInsertPersonSectorInvolvementWithSessionDataCommand
 *
 * @author Reinowin7
 */
class FillInsertPersonSectorInvolvementWithSessionDataCommand implements Command
{
    public function executeCommand($request) 
    {
        // Works similarly to requestProcessor. Only difference is that it does not look a request object 
        // for its data, but session object instead
        // In addition, sectors are requested from the database
        
        $listOfAllSectors = array();
        $personSectorInvolvementFormConverter = null;
        $personSectorInvolvementService = new PersonSectorInvolvementServiceImpl();

        $listOfAllSectors = $personSectorInvolvementService->getListOfAllSectors();
        $personSectorInvolvementFormConverter = new PersonSectorInvolvementFormConverter();


        if (!is_null($listOfAllSectors))
        {
            $personSectorInvolvementFormConverter->setListOfAllSectors($listOfAllSectors);
            $_SESSION["listOfAllSectors"] = $listOfAllSectors;
            $_REQUEST["personSectorInvolvementFormConverter"] = serialize($personSectorInvolvementFormConverter);
        }

        if (isset($_SESSION["personID"]))
        {
            $personID = $_SESSION["personID"];
            $personSectorInvolvementFormConverter->setPersonID($personID);
        }
        if (isset($_SESSION["name"]))
        {
            $name = trim($_SESSION["name"]);
            $personSectorInvolvementFormConverter->setName($name);
        }
        if (isset($_SESSION["sectorSelection[]"]))
        {
            $arrayOfSelectedSectorIDs = $_SESSION["sectorSelection[]"];
            $personSectorInvolvementFormConverter->setArrayOfSelectedSectorIDs($arrayOfSelectedSectorIDs);
        }
        if (isset($_SESSION["agreeToTermsCheckbox"]))
        {
            $agreesToTerms = $_SESSION["agreeToTermsCheckbox"];
            $personSectorInvolvementFormConverter->setAgreesToTerms($agreesToTerms);
        }

        $_REQUEST["personSectorInvolvementFormConverter"] = serialize($personSectorInvolvementFormConverter);
        //$_SESSION["personSectorInvolvementFormConverter"] = $personSectorInvolvementFormConverter;

        return 1;
    }
}

?>
